package com.ky.manage.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ky.manage.R;
import com.ky.manage.model.response.AddressResp;

import java.util.List;

import androidx.annotation.NonNull;

public class AddressAdapter extends BaseQuickAdapter<AddressResp.RowsDTO, BaseViewHolder> {

    List<AddressResp.RowsDTO> list;
    private Context context;
    DeleteListner listner;

    public AddressAdapter(Context context, int layoutId, List<AddressResp.RowsDTO> list, DeleteListner deleteListner) {
        super(layoutId, list);
        this.list = list;
        this.context = context;
        this.listner = deleteListner;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, AddressResp.RowsDTO addressInfo) {
        TextView name = baseViewHolder.findView(R.id.tv_name);
        TextView phoneNum = baseViewHolder.findView(R.id.tv_phonenum);
        TextView address = baseViewHolder.findView(R.id.tv_address);
        ImageView delete = baseViewHolder.findView(R.id.iv_delete_address);
        
        name.setText(addressInfo.getUserName());
        phoneNum.setText(addressInfo.getPhone());
        address.setText(addressInfo.getAddress());
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /*Intent intent = new Intent(context, AddressDetailActivity.class);
                intent.putExtra("type", 1);
                intent.putExtra("addId", addressInfo.getId());
                context.startActivity(intent);*/
                listner.OnAddressDelete(addressInfo.getId());
            }
        });
    }

    public static interface DeleteListner{
        void OnAddressDelete(int key);
    }

}
